package com.ruoyi.web.controller.exam_syllabus;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam_syllabus.domain.TsExamDetails;
import com.ruoyi.exam_syllabus.service.ITsExamDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考试详情Controller
 *
 * @author hongyi
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/exam_syllabus/details")
public class TsExamDetailsController extends BaseController
{
    @Autowired
    private ITsExamDetailsService tsExamDetailsService;

    /**
     * 查询考试详情列表
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(TsExamDetails tsExamDetails)
    {
        startPage();
        List<TsExamDetails> list = tsExamDetailsService.selectTsExamDetailsList(tsExamDetails);
        return getDataTable(list);
    }

    /**
     * 导出考试详情列表
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:details:export')")
    @Log(title = "考试详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TsExamDetails tsExamDetails)
    {
        List<TsExamDetails> list = tsExamDetailsService.selectTsExamDetailsList(tsExamDetails);
        ExcelUtil<TsExamDetails> util = new ExcelUtil<TsExamDetails>(TsExamDetails.class);
        util.exportExcel(response, list, "考试详情数据");
    }

    /**
     * 获取考试详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:details:query')")
    @GetMapping(value = "/{examDetailsId}")
    public AjaxResult getInfo(@PathVariable("examDetailsId") Long examDetailsId)
    {
        return success(tsExamDetailsService.selectTsExamDetailsByExamDetailsId(examDetailsId));
    }

    /**
     * 新增考试详情
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:details:add')")
    @Log(title = "考试详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TsExamDetails tsExamDetails)
    {
//       /* addEdit(tsExamDetails,"add");*/
        return toAjax(tsExamDetailsService.insertTsExamDetails(tsExamDetails));
    }

    /**
     * 修改考试详情
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:details:edit')")
    @Log(title = "考试详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TsExamDetails tsExamDetails)
    {
     //   addEdit(tsExamDetails,"edit");
        return toAjax(tsExamDetailsService.updateTsExamDetails(tsExamDetails));
    }

   /* public void addEdit(TsExamDetails tsExamDetails, String type){
        TsExamDetails pints = tsExamDetailsService.getTsExamDetailsByExamDetailsPints(tsExamDetails.getKnowledgePointsId());
        if(pints!=null){
            if(type.equals("add")) {
                throw new IllegalArgumentException("知识点已经存在");
            } else {
                if(!tsExamDetails.getExamDetailsId().equals(pints.getExamDetailsId())) {
                    throw new IllegalArgumentException("知识点已经存在");
                }
            }
        }
    }*/

    /**
     * 删除考试详情
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:details:remove')")
    @Log(title = "考试详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{examDetailsIds}")
    public AjaxResult remove(@PathVariable Long[] examDetailsIds)
    {
        return toAjax(tsExamDetailsService.deleteTsExamDetailsByExamDetailsIds(examDetailsIds));
    }
}
